import org.junit.jupiter.api.Test;

/**
 * @author 何杰
 * @version 1.0
 */
public class Move {

    public static void main(String[] args) {
        int[] nums = {0,1,0,3,12};
        moveZeroes(nums);
        for (int num : nums) {
            System.out.print(num + "\t");
        }
    }
    public static void moveZeroes(int[] nums) {
        //[0,1,0,3,12]
        int n = nums.length, left = 0, right = 0;
        while(right < n) {
            if(nums[right] != 0) {
                swap(nums, left, right);
                left++;
            }
            right++;
        }
    }

    public static void swap(int[] nums, int left, int right) {
        int temp = nums[left];
        nums[left] = nums[right];
        nums[right] = temp;
    }
}
